/*! =======================================================
                      VERSION  1.1.0
 * ========================================================
 * webpack.prod.config.js
 * ========================================================
 * 本文件为生产发布配置文件
 * 通过 $npm run publish 命令进行打包
 * ======================================================== */
 'use strict';

 let path              = require('path'),
     webpack           = require('webpack'),
     CleanPlugin       = require('clean-webpack-plugin'),
     webpackConfig     = require("./webpack.base.config"),
     HtmlWebpackPlugin = require('html-webpack-plugin'),
     ExtractTextPlugin = require('extract-text-webpack-plugin'),
     _                 = require("lodash");

webpackConfig.plugins.push(
  new CleanPlugin(path.join(__dirname, 'dist/*')),
  new HtmlWebpackPlugin({
      template: path.join(__dirname,'/src/index.html'),
      inject: true
  }),
  // 压缩JS文件
  new webpack.optimize.UglifyJsPlugin({
      output: {
          comments: false,  // remove all comments
      },

      compress: {
        unused: true,
        dead_code: true,
        warnings: false,
        drop_debugger: true,
        drop_console: true
      },
      sourceMap: false
  }),
  new webpack.DefinePlugin({
    'process.env': {
         NODE_ENV: '"production"'
    }
  }),
  new ExtractTextPlugin('[name].css', {
    allChunks: true
  })
)

webpackConfig.module.loaders.filter((loader) =>
  loader.loaders && loader.loaders.find((name) => /css/.test(name.split('?')[0]))
).forEach((loader) => {
  const first = loader.loaders[0]
  const rest = loader.loaders.slice(1)
  loader.loader = ExtractTextPlugin.extract(first, rest.join('!'))
  delete loader.loaders
})


let prodConfig = _.merge(webpackConfig,
{
  entry: {
      // app入口配置
      app: path.join(__dirname, '/src/app.prod.js')
  },
  watch:false
});

let versionPack = require('./version-pack');
module.exports= prodConfig;
